<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
</head>

<body>
    <script>
        let student = {
            name: "翠花",
            age: 18,
            gender: "女",
            hobby: ["跳舞", "唱歌", "rap"],
            friends: [
                { name: "小明", age: 20 },
                { name: "小红", age: 19 },
                { name: "小亮", age: 21 },
                { name: "小丽", age: 22 },
                { name: "小李", age: 23 },
                { name: "小王", age: 24 }
            ]
        };
        // 对象解构获取学生信息
        const { name, age, gender, hobby } = student;
        // 数组解构获取第一个爱好
        const [favHobby,...otherHobbies] = hobby;
        // 数组解构获取第一个朋友信息
        const [friend1] = student.friends;
        console.log(`我的姓名是:${name}`);
        console.log(`我的年龄是:${age}`);
        console.log(`我的性别是:${gender}`);
        console.log(`我最爱的爱好是:${favHobby}`);
        console.log(`我的其他爱好是:${otherHobbies}`);
        console.log(`我最好朋友的信息:${JSON.stringify(friend1)}`);
        // 查找 22 岁的朋友
        const friendWithAge22 = student.friends.find(friend => friend.age === 22);
        if (friendWithAge22) {
            console.log(`我有一个 22 岁的朋友: 名字叫${friendWithAge22.name}`);
        }
    </script>
</body>

</html>